/*
 * @lc app=leetcode id=491 lang=cpp
 *
 * [491] Increasing Subsequences
 */

// @lc code=start
class Solution {
    vector<vector<int>> result;
    vector<int> path;
public:
    vector<vector<int>> findSubsequences(vector<int>& nums) {
        backtrace(nums, 0);
        return result;
    }
    void backtrace(vector<int>&nums, int start_idx) {
        if (path.size() > 1) {
            result.push_back(path);
        }
        unordered_set<int> ss;
        for (int i = start_idx; i < nums.size(); ++i) {
            if (!path.empty() && path.back() > nums[i] || ss.count(nums[i]) > 0) {
                continue;
            }
            path.push_back(nums[i]);
            ss.insert(nums[i]);
            backtrace(nums, i+1);
            path.pop_back();
        }
    }

};
// @lc code=end

